package com.muatocroi.tornado;

import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.os.Build;
import java.net.InetAddress;
import java.net.InterfaceAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.util.ArrayList;
import java.util.Enumeration;

public class AddressLocal {
	@TargetApi(Build.VERSION_CODES.GINGERBREAD)
	public static ArrayList<InetAddress> getBroadcasts() {
		ArrayList<InetAddress> listAddr = new ArrayList<InetAddress>();
		try {
			for (Enumeration<NetworkInterface> en = NetworkInterface
					.getNetworkInterfaces(); en.hasMoreElements();) {
				NetworkInterface intf = en.nextElement();
				for (InterfaceAddress inta : intf.getInterfaceAddresses()) {
					InetAddress adr = inta.getBroadcast();
					if (adr != null)
						listAddr.add(adr);
				}
			}
		} catch (SocketException ex) {
		}
		return listAddr;
	}

	@TargetApi(Build.VERSION_CODES.GINGERBREAD)
	public static ArrayList<InetAddress> getLocals() {
		ArrayList<InetAddress> listAddr = new ArrayList<InetAddress>();
		try {
			for (Enumeration<NetworkInterface> en = NetworkInterface
					.getNetworkInterfaces(); en.hasMoreElements();) {
				NetworkInterface intf = en.nextElement();
				for (InterfaceAddress inta : intf.getInterfaceAddresses()) {
					InetAddress adr = inta.getBroadcast();
					if (adr != null)
						listAddr.add(inta.getAddress());
				}
			}
		} catch (SocketException ex) {
		}
		return listAddr;
	}
}
